package com.gzhu.knowledgeAdmin.common.exception;

import com.gzhu.knowledgeAdmin.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author laoba
 * @create 2022-11-03 23:49
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    public R error(Exception e){
        e.printStackTrace();
        return R.error();
    }

    //自定义异常
    @ExceptionHandler(BusinessException.class)
    public R error(BusinessException e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error(e.getCode(),e.getMessage());
    }
}
